#练习一遍
s1='taiBAi'
print(s1.capitalize())#首字母大写 Taibai
print(s1.swapcase())#大小写翻转 TAIbaI

msg='taibai say hi'
print(msg.title())#Taibai Say Hi

s1='barry'
print(s1.center(20,'*'))

#find 通过元素找索引，找到第一个返回，找不到返回-1
print(s1.find('a'))#1
print(s1.find('x'))#-1
# index 找不到报错
print(s1.index('a'))
#print(s1.index('o')) ValueError: substring not found

#list
l1=[11,22,33,44,55]
for i in range(len(l1)):
    if i %2==1:
        l1.pop(i)
print(l1)
l1=[11,22,33,44,55]
for i in range(len(l1)-1,-1,-1):
    if i %2==1:
        l1.pop(i)
print(l1)
l1=[11,22,33,44,55]
del l1[1::2]
print(l1)

#字典 补充 uppdate,更新，增加值，修改值，创建字典，将一个字典的所有键值对覆盖添加到另一个字典
dic={'name':'太白','age':18}
dic.update(hobby='运动',hight='175')
print(dic)
dic.update(name='太白金星')
print(dic)

#fromkeys dict.fromkeys(iterable,value)，iterable里的都是键
dic=dict.fromkeys('abc',100)
print(dic)
dic=dict.fromkeys([1,2,3],'alex')
print(dic)
#坑:值共用一个
dic=dict.fromkeys([1,2,3],[])
print(dic)
dic[1].append(666)
print(dic)

dic={'k1':'太白','k2':'barry','k3':'白白','age':18}
#将字典中含有'k'元素的键值对删除
# for key in dic:
#     if 'k' in key:
#         dic.pop(key)
# print(dic)#RuntimeError: dictionary changed size during iteration,循环字典时，如果改变这个字典的大小，就会报错
l1=[]
for key in dic:
    if 'k' in key:
        l1.append(key)
for i in l1:
    dic.pop(i)
print(dic)

for key in list(dic.keys()):
    if 'k' in key:
        dic.pop(key)
print(dic)

for key in list(dic):
    if 'k' in key:
        dic.pop(key)
print(dic)